package com.aaa.rabbitmq.one;

import com.aaa.rabbitmq.one.util.RabbitMQUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 *
 * 消费者
 * zhc
 */
public class Consumer {
    //队列名称
    public static final String QUEUE_NAME="helloTest";
    //接收消息
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtil.getChannel();
        //声明接受消息
        DeliverCallback deliverCallback = (var1,var2)->{
            System.out.println(new String(var2.getBody()));
        };
        //取消消息的
        CancelCallback cancelCallback = consumerTag ->{
            System.out.println("消息消费被中断");
        };
        //消费者接受/消费消息
        //1 消费队列，2消费成功是否自动应答，3，消费者未成功消费的回调 4,消费者取消消费的回调
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);

    }
}
